//
//  LGPatientDetailItemCell.m
//  HeartDiseaseManage
//
//  Created by Bovin on 2023/9/8.
//  检查报告 -- 随访记录

#import "LGPatientDetailItemCell.h"
#import "LGPatientDetailItemView.h"
#define itemWidth   (Screen_W-viewPix(44))/2.0
#define itemHeight  viewPix(75)
@interface LGPatientDetailItemCell()
/**  检查报告 */
@property (nonatomic , strong)LGPatientDetailItemView *inspectionView;
/**  体征监测 */
@property (nonatomic , strong)LGPatientDetailItemView *monitorView;
/**  随访记录 */
@property (nonatomic , strong)LGPatientDetailItemView *followupView;
/**  运动康复 */
@property (nonatomic , strong)LGPatientDetailItemView *sportView;
/**  用药管理 */
@property (nonatomic , strong)LGPatientDetailItemView *medicineView;

@end

@implementation LGPatientDetailItemCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    //检查报告
    NSDictionary *inspectDic = dataDic[@"exams"];
    if(inspectDic.allKeys.count>0){
        NSString *date = LGNSString(inspectDic[@"date"]);
        date = [date isEmptyString]?@"":date;
        NSString *content = [NSString stringWithFormat:@"%@ 更新方案",date];
        self.inspectionView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, content.length-4)];
    }else{
        self.inspectionView.contentLabel.attributedText = [@"近30天暂无报告" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 8)];
    }
    
    //体征监测
    NSDictionary *monitorDic = dataDic[@"monitor"];
    if([monitorDic allKeys].count>0){
        NSString *content = [NSString stringWithFormat:@"%@ 血压 %@/%@ %@",monitorDic[@"date"],monitorDic[@"sbp"],monitorDic[@"dbp"],monitorDic[@"pulse"]];
        self.monitorView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#3291FF"]} range:NSMakeRange(8, content.length-8)];
    }else{
        self.monitorView.contentLabel.attributedText = [@"暂无血压记录" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 6)];
    }
    
    //用药管理
    NSDictionary *medicineDic = dataDic[@"medicine"];
    if(medicineDic.allKeys.count>0){
        NSString *content = [NSString stringWithFormat:@"%@ 更新方案",medicineDic[@"date"]];
        self.medicineView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, content.length-4)];
    }else{
        self.medicineView.contentLabel.attributedText = [@"暂无方案" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 4)];
    }
    
    //运动康复
    NSDictionary *sportDic = dataDic[@"sport"];
    if(sportDic.allKeys.count>0){
        NSString *content = [NSString stringWithFormat:@"%@ 更新方案",sportDic[@"date"]];
        self.sportView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, content.length-4)];
    }else{
        self.sportView.contentLabel.attributedText = [@"暂无方案" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 4)];
    }
    
    //随访记录
    NSDictionary *followDic = dataDic[@"advice"];
    if(followDic.allKeys.count>0){
        NSString *content = [NSString stringWithFormat:@"%@ 更新记录",followDic[@"date"]];
        self.followupView.contentLabel.attributedText = [content attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#333333"]} range:NSMakeRange(0, content.length-4)];
    }else{
        self.followupView.contentLabel.attributedText = [@"暂无随访记录" attributeString:@{NSForegroundColorAttributeName:[UIColor colorWithString:@"#666666"]} range:NSMakeRange(0, 6)];
    }
}

-(void)checkItemDetailAction:(UITapGestureRecognizer *)sender{
    CGPoint point = [sender locationInView:self.contentView];
    if(CGRectContainsPoint(self.inspectionView.frame, point)){
        //检查报告
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkInspectionReport)]){
            [self.delegate checkInspectionReport];
        }
    }else if (CGRectContainsPoint(self.monitorView.frame, point)){
        //体征监测
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkMonitorData)]){
            [self.delegate checkMonitorData];
        }
    }else if (CGRectContainsPoint(self.medicineView.frame, point)){
        //用药管理
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkMedicineController)]){
            [self.delegate checkMedicineController];
        }
    }else if (CGRectContainsPoint(self.sportView.frame, point)){
        //运动康复
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkSportsController)]){
            [self.delegate checkSportsController];
        }
    }else if (CGRectContainsPoint(self.followupView.frame, point)){
        //随访记录
        if(self.delegate && [self.delegate respondsToSelector:@selector(checkFollowupRecord)]){
            [self.delegate checkFollowupRecord];
        }
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkItemDetailAction:)]];
    [self.contentView addSubview:self.inspectionView];
    [self.contentView addSubview:self.followupView];
    [self.contentView addSubview:self.monitorView];
    [self.contentView addSubview:self.sportView];
    [self.contentView addSubview:self.medicineView];
    [self.medicineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.monitorView.mas_bottom).offset(viewPix(16));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
        make.height.equalTo(@(itemHeight));
    }];
}

-(LGPatientDetailItemView *)inspectionView{
    if(!_inspectionView){
        _inspectionView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(8), itemWidth, itemHeight)];
        [_inspectionView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _inspectionView.backgroundColor = [UIColor whiteColor];
        _inspectionView.title = @"报告中心";
        _inspectionView.contentLabel.text = @"近30天暂无报告";
    }
    return _inspectionView;
}

-(LGPatientDetailItemView *)followupView{
    if(!_followupView){
        _followupView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(kMaxX(self.inspectionView.frame)+viewPix(12), kMinY(self.inspectionView.frame), itemWidth, itemHeight)];
        [_followupView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _followupView.backgroundColor = [UIColor whiteColor];
        _followupView.title = @"随访及医嘱记录";
        _followupView.contentLabel.text = @"暂无随访记录";
    }
    return _followupView;
}


-(LGPatientDetailItemView *)monitorView{
    if(!_monitorView){
        _monitorView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.inspectionView.frame)+viewPix(16), itemWidth, itemHeight)];
        [_monitorView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _monitorView.backgroundColor = [UIColor whiteColor];
        _monitorView.title = @"体征监测";
        _monitorView.contentLabel.text = @"暂无血压记录";
    }
    return _monitorView;
}

-(LGPatientDetailItemView *)sportView{
    if(!_sportView){
        _sportView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(kMaxX(self.monitorView.frame)+viewPix(12), kMinY(self.monitorView.frame), itemWidth, itemHeight)];
        [_sportView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _sportView.backgroundColor = [UIColor whiteColor];
        _sportView.title = @"生活方式记录";
        _sportView.contentLabel.text = @"暂无方案";
    }
    return _sportView;
}

-(LGPatientDetailItemView *)medicineView{
    if(!_medicineView){
        _medicineView = [[LGPatientDetailItemView alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.monitorView.frame)+viewPix(16), Screen_W-viewPix(32), itemHeight)];
        [_medicineView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _medicineView.backgroundColor = [UIColor whiteColor];
        _medicineView.title = @"用药管理";
        _medicineView.contentLabel.text = @"暂无方案";
    }
    return _medicineView;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
